package cn.lichenes.repository;

import cn.lichenes.entity.Phone;
import cn.lichenes.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface UserRepository extends JpaRepository<User,Integer>,JpaSpecificationExecutor<User>{

    @Query(value = "from User u join u.userStatus s where u.uAccount= :account and u.uPassword= :password and s.id=2")
    User checkAdmin(@Param("account") String account,@Param("password") String password);

    @Query(value = "update User u set u.userStatus = :status where u.uId = :id")
    Integer banUser(@Param("id") Integer id,@Param("status") Integer status);

    @Query(value = "from User u join u.userStatus s where u.uPhone= :phone and s.id=1")
    User checkPhone(@Param("phone") String phone);

    @Query(value = "from User u join u.userStatus s where u.uEmail= :email and u.uPassword= :password and s.id=1")
    User ckeckEmail(@Param("email") String email,@Param("password") String password);

    @Query(value = "from User u join u.userStatus s where u.uAccount= :name and u.uPassword= :password and s.id=1")
    User checkUser(@Param("name") String name,@Param("password") String password);

    User findByuEmail(String email);

    User findByuAccount(String name);

    User findByuPhone(String phone);
}
